//app.js
const common = require("./common/common")
App({
	onLaunch: function () {
		// 获取小程序发布状态
		common.getAppLetStatus().then(res => {
			console.log("获取小程序发布状态",res)
			this.globalData.APPLETSTATUS = res
		})
		// 全局自定义导航栏高度适配
		// 感谢博主的计算公式 https://www.cnblogs.com/sese/p/9761713.html
		// 发现BUG：适配导航栏高度时，注意微信小程序的胶囊按钮有上下2px的外边距
		let menuButtonObject = wx.getMenuButtonBoundingClientRect();
		wx.getSystemInfo({
			success: res => {
				console.log(res)
				// 计算
				let statusBarHeight = res.statusBarHeight,
					navTop = menuButtonObject.top,
					navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2,
					capsuleBtnWidth = menuButtonObject.width + (res.windowWidth - menuButtonObject.right) * 2;
				// 赋值
				this.globalData.navHeight = navHeight; // 导航栏整体高度(信号栏 + 胶囊按钮栏)
				this.globalData.navContentHeight = menuButtonObject.height; // 导航栏内容区高度(胶囊按钮栏)
				this.globalData.navTop = navTop; //胶囊按钮与顶部的距离
				this.globalData.capsuleBtnWidth = capsuleBtnWidth // 胶囊按钮所占宽度(屏幕宽度-胶囊右边界坐标=胶囊右侧外边距)
				this.globalData.windowWidth = res.windowWidth // 手机屏幕宽度
				this.globalData.windowHeight = res.windowHeight
				this.globalData.navigationBarHeight = res.statusBarHeight + res.navigationBarHeight;
				this.globalData.statusBarHeight = res.statusBarHeight;
			},
			fail(err) {
				console.error(err);
			}
		})
		this.globalData.user.wxLoginUsername = wx.getStorageSync('wxLoginUsername')
		this.globalData.user.wxLoginStatus = wx.getStorageSync('wxLoginStatus')
		this.globalData.user.wxUserId = wx.getStorageSync('wxUserId')
		this.globalData.user.wxLoginPhone = wx.getStorageSync('wxLoginPhone')
		this.globalData.user.wxLoginImg = wx.getStorageSync('wxLoginImg') ? wx.getStorageSync('wxLoginImg') : '/assets/img/user_logo.png'
		this.globalData.user.wxLoginOpenid = wx.getStorageSync('wxLoginOpenid')
		this.globalData.user.wechatUserId = wx.getStorageSync('wechatUserId')

	},
	// 全局公用变量
	// 使用方式
	// //获取应用实例
	// const App = getApp()
	// App.globalData.navHeight
	globalData: {
		APPLETSTATUS: "prod", // 小程序发布状态，控制审核内容不通过问题 dev 开发/prod 生产
		navHeight: null,
		navContentHeight: null,
		navTop: null,
		capsuleBtnWidth: null,
		windowWidth: null,
		windowHeight: null,
		navigationBarHeight: null,
		statusBarHeight: null,
		onShareAppMessage: {
			title: "唯达宁 放心管用的药",
			path: "/pages/index/index",
			imageUrl: "/assets/img/logo.png",
		},
		user: {
			wxLoginStatus: false,
			wxUserId: "",
			wxLoginPhone: "",
			wxLoginUsername: "微信用户",
			wxLoginImg: "/assets/img/user_logo.png",
			wxLoginOpenid: "",
			wechatUserId: "",
		}
	},


})